package main

import (
	"crypto/rand"
	"fmt"
	"os"
	"sort"
)

func main() {
	values := make([]byte, 32*1024*1024)
	if _, err := rand.Read(values); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	values1 := make([]byte, 32*1024*1024)
	if _, err := rand.Read(values1); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	done := make(chan struct{})
	fmt.Println(sort.SliceIsSorted(values, func(i, j int) bool { return values[i] < values[j] }), values[0], values[len(values)-1])
	fmt.Println(sort.SliceIsSorted(values1, func(i, j int) bool { return values1[i] < values1[j] }), values1[0], values1[len(values1)-1])

	// sorting goroutine
	go func() {
		sort.Slice(values, func(i, j int) bool {
			return values[i] < values[j]
		})

		// notify that sorting is done.
		done <- struct{}{}
	}()

	go func() {
		sort.Slice(values1, func(i, j int) bool {
			return values1[i] < values1[j]
		})

		// notify that sorting is done.
		done <- struct{}{}
	}()

	// wait for notification
	<-done
	<-done

	fmt.Println(sort.SliceIsSorted(values, func(i, j int) bool { return values[i] < values[j] }), values[0], values[len(values)-1])
	fmt.Println(sort.SliceIsSorted(values1, func(i, j int) bool { return values1[i] < values1[j] }), values1[0], values1[len(values1)-1])

}
